<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta name="format-detection" content="telephone=no" />
    <title>修改密码</title>
    <link rel="stylesheet" href="../../css/reset.css">
    <style>
        body {
            width: 100%;
            background-color: #f5f5f5;
            font-size: 0.28rem;
            /*padding-top: 0.5rem;*/
            height: auto;
            -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
            font-family: Helvetica;
            color: #333333;
        }

        .head {
            width: 100%;
            height: 0.88rem;
            background-color: #ffffff;
            display: flex;
            display: -webkit-flex;
            padding: 0 0.24rem;
            justify-content: space-between;
            -webkit-justify-content: space-between;
            align-items: center;
            -webkit-align-items: center;
            box-sizing: border-box;
            border-bottom: 0.01rem solid #e5e5e5;
            font-size: 0.36rem;
        }

        .head img {
            width: 0.21rem;
            height: 0.36rem;
        }

        .head_title {
            flex: 1;
            text-align: center;
            font-size: 0.36rem;
            color: #333333;
        }

        .reset {
            padding: 0 0.24rem;
            margin-top: 0.2rem;
            display: flex;
            display: -webkit-flex;
            flex-direction: column;
            -webkit-flex-diectiion: column;
            background-color: white;
            border-bottom: 0.01rem solid #e5e5e5;
        }

        .reset input {
            border: none;
            height: 0.88rem;
            line-height: 0.88rem;
            font-size: 0.28rem;
            outline: none;
            border-bottom: 0.01rem solid #e5e5e5;
            color: #333333;
            padding-left: 0.1rem;
        }

        .reset input:last-of-type {
            border: none;
        }

        .reset input::-webkit-input-placeholder {
            font-size: #cccccc;
            font-size: 0.28rem;
        }

        .camp {
            margin: auto;
            margin-top: 1.2rem;
            color: white;
            font-size: 0.32rem;
            text-align: center;
            height: 0.88rem;
            width: 85%;
            line-height: 0.88rem;
            background: #e1e1e1;
            background-size: cover;
            border-radius: 0.08rem;
        }

        .submit {
            margin: auto;
            margin-top: 1.2rem;
            color: white;
            font-size: 0.32rem;
            text-align: center;
            height: 0.88rem;
            width: 85%;
            line-height: 0.88rem;
            background-color: #ffd203;
        }
    </style>
</head>

<body>
    <div class="reset">
        <input type="password" name="" id="oldpass" placeholder="请输入旧密码">
        <input type="password" name="" id="newpass" placeholder="请输入新密码">
        <input type="password" name="" id="passagin" placeholder="再次输入密码">
    </div>
    <div class="camp">
        完成
    </div>
    <script src="../../script/autosize.js"></script>
    <script src="../../script/fastclick.js"></script>
    <script src="../../script/jquery_three_two_one.js"></script>
    <script src="../../script/app.js"></script>
    <script>
        apiready = function () {
            var app = new APP();
            app.headerMap();
            if (app.ST == "ios") {
                $("input").click(function () {
                    $(this)
                        .focus()
                        .select(); //保险起见，还是加上这句。
                });
            }
            var account = app.getAccount();
            // 获取用户余额
            var oldPws = false,
                newPws = false,
                repPws = false;
            function allowSubmit() {
                if (oldPws == true && newPws == true && repPws == true) {
                    $(".camp").addClass('submit').unbind('click').on("click", function () {
                        var newpass = $("#newpass").val().trim();
                        var passagin = $("#passagin").val().trim();
                        var oldpass = $("#oldpass").val().trim();
                        // var reg = /^\w{6,}$/;
                        if (!newpass || !passagin || !oldpass) {
                            app.toast("密码不能为空");
                            return
                        }
                        if (newpass.length < 6 || passagin.length < 6) {
                            app.toast("请至少设置6位密码");
                            return
                        }
                        if (newpass !== passagin) {
                            app.toast("输入密码不一致");
                            return
                        }
                        app.ajaxPro({
                            url: "member/change-password",
                            values: {
                                token: account.token,
                                password: oldpass,
                                new_password: newpass
                            },
                            openFlower: true
                        }, function (ret) {
                            app.trigger("quit_login");
                            if (ret.code == 200) {
                                app.toast("修改密码成功!请使用新的密码登陆");
                                // 广播注销登录事件
                                app.closeW();
                            } else {
                                app.toast(ret.message);
                            }
                        });
                    });
                } else {
                    $(".camp").removeClass('submit').unbind('click');
                }
            }
            $('#oldpass').keyup(function () {
                if (!$(this).val()) {
                    oldPws = false
                } else {
                    oldPws = true;
                }
                allowSubmit();
            });
            $('#newpass').keyup(function () {
                if (!$(this).val()) {
                    newPws = false
                } else {
                    newPws = true;
                }
                allowSubmit();
            });
            $('#passagin').keyup(function () {
                if (!$(this).val()) {
                    repPws = false
                } else {
                    repPws = true;
                }
                allowSubmit();
            });
            app.listen("tryLogin", function (params) {
                app.closeW();
            })
        };
    </script>
</body>

</html>